package com.arcsoft.crud.limitNumber.task;

import java.util.Date;
import java.util.Map;

import com.arcsoft.crud.Constants.Global;
import com.arcsoft.crud.limitNumber.base.BenchmarkBase;
import com.arcsoft.crud.limitNumber.base.BenchmarkTask;
import com.arcsoft.crud.util.ConnectionDB;
import com.arcsoft.log.entity.OptimizeAnalyzeLog;

public class DeleteTask extends BenchmarkTask{

	public DeleteTask(int index, BenchmarkBase parent, int printInfoInterval, long loopCount, String taskLogTable) {
		super(index, parent, printInfoInterval, loopCount, taskLogTable);
	}

	@Override
	public String execute(int loopIndex){
       // ConnectionDB db = new ConnectionDB();
         
        Map<String, Long> map = prepareData();
        
        String sql = "delete from people where id = ?";
        
        long startId =map.get("startId");
        //long scope = map.get("scope");
        long param =(long)(Math.random()*(map.get("endId")-map.get("startId")))+startId;
         
        Object arrays[] = {param};
         
       // int line = db.updateBySql(sql, arrays);
        
        return parseSql(sql, arrays);
	}
	
	@Override
	public void logInfo(Date startTime, Date endTime, String requestDetail, int extendTime){
		
		String sceneDesc = Global.OPERATOR_TYPE_DELETE+"-"+Global.THREAD_COUNT+"C-"+Global.LOOP_COUNT+"L";//场景名命名规则 操作类型-并发数C-循环次数L
		
		OptimizeAnalyzeLog optimizeAnalyzeLog = new OptimizeAnalyzeLog
					(sceneDesc,Global.OPERATOR_TYPE_DELETE,startTime, endTime, extendTime, requestDetail);
		
		insertLog(optimizeAnalyzeLog);
	}

}
